//==========================================================================
// Copyright (c) 2000-2009,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CGRAFIXEVENTBUFFER_H__
#define __CGRAFIXEVENTBUFFER_H__

typedef enum {
    NotifyType_None = 0,
    NotifyType_Timer = 1,
    NotifyType_Paint = 2,
    NotifyType_Close = 3,
    NotifyType_Shine = 4,
    NotifyType_BufferChanged = 5,
    NotifyType_OrientationChanged = 6,
} NotifyType;

#include <engine.h>

#define _NO_CGRAFIXEVENTBUFFER_CLASSOBJECT_
#include "_CGrafixEventBuffer.h"

#define     EVENTBUFFER_SIZE            128

class EventLink : public DLinkNode {
public:
    EventLink() {
        Initialize();
    }

    GrafixObjectEvent event;
    Int32 appletId;
};

class CGrafixObject;
class GrafixObjectStack;

CarClass(CGrafixEventBuffer), public DLinkNode
{
public:
    CGrafixEventBuffer () {
        Initialize();
        m_event = NULL;
        m_stack = NULL;
    }

    ~CGrafixEventBuffer();

    CARAPI constructor(
        /* [in] */Int32 contextId,
        /* [in] */ GrafixObjectStack * stack);

    Void Lock()
    {
        m_lock.Lock();
    }

    Void Unlock()
    {
        m_lock.Unlock();
    }

    Void *operator new(size_t size, void * pv) { return pv; }

    Void *operator new(size_t size) { return malloc(size); }

    Void operator delete(void * pv) { free(pv); }

public:
    CARAPI GetEvent(
        /* [out] */ struct GrafixObjectEvent * pEvent);

public:
    ECode AddEvent(
        /* [in] */ const GrafixObjectEvent& event,
        /* [in] */ GrafixObjectProperty status);

    ECode AddNotifyEvent(
        /* [in] */ Int32 appletId,
        /* [in] */ const GrafixObjectEvent& event);

    Void CleanEvent(
        /* [in] */ CGrafixObject * pObject);

    ECode Notify(
        /* [in] */ Int32 type);

    Boolean HandleCloseEvent(
        /* [out] */ GrafixObjectEvent * pEvent);

    Boolean HandlePaintEvent(
        /* [out] */ GrafixObjectEvent * pEvent);

    Boolean HandleShineEvent(
        /* [out] */ GrafixObjectEvent * pEvent);

    Boolean HandleOrientationChangedEvent(
        /* [out] */ GrafixObjectEvent * pEvent);

    Boolean HandleBufferChangedEvent(
        /* [out] */ GrafixObjectEvent * pEvent);

    Boolean HandleTimeEvent(
        /* [out] */ GrafixObjectEvent * pEvent);

public:
    Int32 m_contextId;

    GrafixObjectStack* m_stack;

    IEvent* m_event;

    VinciLock m_lock;

    EventLink m_availableEventHeader;
    EventLink m_unavailingEventHeader;

    GrafixObjectEvent m_events[EVENTBUFFER_SIZE];
    GrafixObjectEvent m_lastEvent;

    Int32 m_set;
    Int32 m_get;

    Boolean m_timer;
    Boolean m_paint;
    Boolean m_closed;
    Boolean m_shine;
    Boolean m_bufferChanged;
    Boolean m_orientationChanged;

    Int32 m_order;
};

#endif // __CGRAFIXEVENTBUFFER_H__
